package com.kedi.welfarecenter.controller;




import com.kedi.welfarecenter.controller.operationcenter.CommunityPenSecurityController;
import com.kedi.welfarecenter.enums.ResultEnum;
import com.kedi.welfarecenter.exception.CommonException;
import com.kedi.welfarecenter.utils.ResultVoUtil;
import com.kedi.welfarecenter.vo.ResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



import com.kedi.welfarecenter.service.WelfareService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
* @Description: app惠老福利接口
* @author: dw 
* @date: 2019 2019年7月9日 上午11:17:54
 */
@RestController
public class WelfareController {
	private static Logger logger = LoggerFactory.getLogger(CommunityPenSecurityController.class);
	 @Autowired
	    private WelfareService elderlyHealthService;
	   
        /**
         * @Description:长者就业列表
         * @return
         */
	    @RequestMapping(value = "/job/list")
	    public List<Map> getJobList() {
	    	
	        return elderlyHealthService.getJobList();
	    }
	    /**
         * @Description:长者就业详情
         * @return
         */
	    @RequestMapping(value = "/job/detail")
	    public Map getJobDetail(Integer id) {
	    	
	    	return elderlyHealthService.getJobDetail(id);
	    }
	@RequestMapping(value = "/job/phoneapplicant")
	public ResultVo findPhone(@RequestParam("job_id") Integer job_id, @RequestParam("p_user_id") Integer p_user_id){

		HashMap<String, Object> map = new HashMap<>(5);
		map.put("job_id",job_id);
		map.put("p_user_id",p_user_id);
		Map res = elderlyHealthService.finddeliverid(map);
		if(res==null){
			elderlyHealthService.insertdeliver(map);
			Map<String, Object> phone = elderlyHealthService.findPhone(p_user_id);
			return ResultVoUtil.success(phone);
		}else {
			logger.info("长者就业电话申请已经注册报名");
			throw new CommonException(ResultEnum.EXISTED_THE_RECORD);
		}
	}
}
